package com.dgut.admin.service.impl;

import com.dgut.common.mapper.OrderDetailMapper;
import com.dgut.common.param.OrderListParam;
import com.dgut.common.result.CategoryWeightData;
import com.dgut.common.result.OrderSevenDayData;
import com.dgut.admin.service.StatisticsService;
import com.dgut.common.mapper.CollectionOrderMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @Author zyq
 * @Date 2022/4/18 12:52
 * @Description TODO
 * @Version 1.0
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class StatisticsServiceImpl implements StatisticsService {

    private final CollectionOrderMapper orderMapper;
    private final OrderDetailMapper detailMapper;

    @Override
    public List<OrderSevenDayData> sevenDayOrder() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,-6);
        List<OrderSevenDayData> res = new ArrayList<>();
        while (!calendar.after(Calendar.getInstance())) {
            OrderSevenDayData data = orderMapper.countByDate(calendar.getTime());
            data.setDay(calendar.getTime());
            res.add(data);
            calendar.add(Calendar.DATE, 1);
        }
        return res;
    }

    @Override
    public List<CategoryWeightData> categoryWeight(OrderListParam param) {
        return detailMapper.categoryData(param.getBeginTime(), param.getEndTime());
    }
}
